package eddy.yang.wordpad;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

public class EddyWordPad {
	private JFrame frame;
	private JLabel splashLabel;
	private WordPadFrame myframe = new WordPadFrame("Eddy WordPad");
	private JWindow splashScreen = null;
	
	public static void main(String[] args) {
		final EddyWordPad eddypad = new EddyWordPad();
		eddypad.createSplashScreen();
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				eddypad.splashScreen.setVisible(true);
			}
		});
		
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				eddypad.splashScreen.setVisible(false);
				eddypad.splashScreen = null;
				eddypad.splashLabel = null;
				eddypad.showEddyPad();
			}
		});
	}
	
	public void showEddyPad() {		
		myframe.setSize(800,600);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		myframe.setLocation(d.width/2 - myframe.getWidth()/2, d.height/2 - myframe.getHeight()/2);
		myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		myframe.setVisible(true);
	}
	
	public void createSplashScreen() {
		URL url = EddyWordPad.class.getResource("resources/Splash.jpg");
		splashLabel = new JLabel(new ImageIcon(url));
		splashScreen = new JWindow(frame);
		splashScreen.getContentPane().add(splashLabel);
		splashScreen.pack();
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		splashScreen.setLocation(d.width/2 - splashScreen.getWidth()/2, d.height/2 - splashScreen.getHeight()/2);		
	}
}
